package net.wanho.util;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet工具类
 */
public class ServletUtils {

    public static ServletRequestAttributes getRequestAttributes(){
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        return  (ServletRequestAttributes)requestAttributes;
    }

    /**
     * 获取请求对象
     * @return
     */
    public  static HttpServletRequest getRequest(){
        return getRequestAttributes().getRequest();
    }

    /**
     * 获取响应请求
     * @return
     */
    public  static HttpServletResponse getResponse(){
        return getRequestAttributes().getResponse();
    }
}
